<?php

namespace app\admin\model\fzdc\point;

use think\Model;
use traits\model\SoftDelete;

class Goods extends Model
{

    use SoftDelete;


    // 表名
    protected $name = 'fzdc_pointgoods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];


    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1')];
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getThumbnailAttr($value, $data)
    {
        return cdnurl($value, true);
    }


    public function coupon()
    {
        return $this->belongsTo('app\admin\model\fzdc\coupon\Coupon', 'coupon_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function type()
    {
        return $this->belongsTo('app\admin\model\fzdc\pointgoods\Type', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
